using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.SystemConsole.Themes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Simple.Admin.WebApi
{
    public class Program
    {
        public static void Main(string[] args)
        {
#if DEBUG
            Log.Logger = new LoggerConfiguration()
                            .ReadFrom.Configuration(new ConfigurationBuilder()
                            .AddJsonFile("SerilogConfig.json", optional: true, reloadOnChange: true).Build())
                            .CreateLogger();
            //Log.Logger = new LoggerConfiguration()
            //               .MinimumLevel.Debug()
            //               .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
            //               .MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
            //               .MinimumLevel.Override("System", LogEventLevel.Warning)
            //               .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
            //               .CreateLogger();
#else
            Log.Logger = new LoggerConfiguration()
                             .ReadFrom.Configuration(new ConfigurationBuilder()
                             .AddJsonFile("SerilogConfig.json", optional: true, reloadOnChange: true).Build())
                             .CreateLogger();
#endif
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .ConfigureLogging(p => p.ClearProviders()).UseSerilog()
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
}
